{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d03615a7-8744-4cf6-9b70-dfe2987a14ac",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# 读取 CSV 文件\n",
    "file_path = '../dataset/PestDetectionv5Dataset/csv/all/merged_dataset.csv'  # 替换为你的文件路径\n",
    "data = pd.read_csv(file_path)\n",
    "\n",
    "# 分层切割数据集\n",
    "# 不使用分层抽样\n",
    "train_data, test_data = train_test_split(data, test_size=0.1)\n",
    "\n",
    "\n",
    "# 保存训练集和测试集\n",
    "train_data.to_csv('../dataset/PestDetectionv5Dataset/csv/train/train_data.csv', index=False)\n",
    "test_data.to_csv('../dataset/PestDetectionv5Dataset/csv/val/test_data.csv', index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5136a6f2-59f2-42be-9361-c83d774d50d0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
